package edu.ccut.saturn.studio.core.util.eclipse;

/**
 * @author Bai Yucheng
 * 
 * 创建时间：2007-11-6 上午09:09:25
 * 
 */
public class SaturnValidation {
	/**
	 * 判断是否为规定格式
	 */
	public static boolean isOK(String str, String my) {
		boolean isOk = false;
		if (str.endsWith(my)) {
			if (str.indexOf('.') == -1) {
				isOk = true;
			}		
		}
		return isOk;
	}
	
	/**
	 * 判断是否包含"."
	 * 
	 */
	public static boolean isHasDot(String str) {
		return str.matches(".*\\..*");
	}
	
	/**
	 * 判断首字母是否大写
	 * 
	 */
	public static boolean isPriUpper(String str) {
		return str.matches("[A-Z|_]{1}.*");
	}
	
	/**
	 * 判断第一位是否是数字
	 * 
	 */
	public static boolean isPriNum(String str) {
		return str.matches("[0-9]{1}.*");
	}
	
	/**
	 * 判断是否为字母、数字或"_"
	 * 
	 */
	public static boolean isValidProgramStr(String str) {
		return str.matches("[a-zA-Z0-9_]*");
	}
	
	/**
	 * 判断是否为字母、数字、"_"或"."
	 */
	public static boolean isValidProgramDOtStr(String str) {
		return str.matches("[a-zA-Z0-9_.]*");
	}
	
	/**
	 * 判断是否是数字
	 * 
	 */
	public static boolean isInt(String str) {
		return str.matches("[0-9]*");
	}
	
	/**
	 * 判断是否为空
	 */
	public static boolean isEmpty(String str) {
		if (str == null || str.trim().length() == 0) {
			return true;
		}
		return false;
	}
	
	/**
	 * 判断是否为中文
	 * @param str
	 * @return
	 */
	public static boolean isGB2312(String str) {
		char[] chars = str.toCharArray();
		boolean isGB2312 = false;
		for (int i = 0; i < chars.length; i++) {
			byte[] bytes = ("" + chars[i]).getBytes(); //$NON-NLS-1$
			if (bytes.length == 2) {
				int[] ints = new int[2];
				ints[0] = bytes[0] & 0xff;
				ints[1] = bytes[1] & 0xff;
				if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40
						&& ints[1] <= 0xFE) {
					isGB2312 = true;
					break;
				}
			}
		}
		return isGB2312;
	}

	/**
	 * 判断是否为非法字符
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isBadWord(String str) {
		String badword = "'~`@#$%^&*()=+|{}[]\\"; //$NON-NLS-1$
		char[] chars = str.toCharArray();
		boolean isBadWord = false;
		for (int i = 0; i < chars.length; i++) {
			if (badword.indexOf(chars[i]) >= 0) {
				isBadWord = true;
			}
		}
		return isBadWord;
	}
	
	/**
	 * 判断是否含空格
	 */
	public static boolean isHasSpace(String str) {
		return str.indexOf(" ") > -1;
	}
	
	/**
	 * 判断是否是数字、小圆点
	 */
	public static boolean isNumberDot(String str) {
		return str.matches("[0-9.]*");
	}
}
